#include <stdio.h>
#include <stdint.h>
#include <webrtc/modules/audio_processing/ns/include/noise_suppression.h>
#include <webrtc_audio_processing/webrtc/modules/audio_processing/ns/ns_core.h>
#include "audio_ns.h"
#ifdef DMALLOC
#include <imp/dmalloc.h>
#endif
NsHandle* audio_process_ns_create()
{
	NsHandle* handle_ns;
	handle_ns = WebRtcNs_Create();

	return handle_ns;
}

int audio_process_ns_set_config(NsHandle *handle,int samplerate,int mode)
{
	if(NULL == handle)
		return -1;
	int nRet = 0;
	nRet = WebRtcNs_Init(handle,samplerate);
	if(nRet != 0)
		return -1;
	nRet = WebRtcNs_set_policy(handle, mode);
	if(nRet != 0)
		return -1;

	return 0;
}

void audio_process_ns_get_config()
{
	return;
}

void audio_process_ns_process(NsHandle* handle,const float* const* spframe,int num_bands,float* const* outframe)
{
	if(NULL == handle||NULL == spframe||NULL == *spframe
	||NULL == outframe||NULL == *outframe||0 == num_bands)
		return;
	WebRtcNs_Analyze(handle,*spframe);
	WebRtcNs_Process(handle, spframe, num_bands, outframe);
}

void audio_process_ns_free(NsHandle* handle)
{
	WebRtcNs_Free(handle);
}

